import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/repair_factory/accessories_query/repairs_inquiry.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';
class VINQuery extends StatefulWidget {
  @override
  _VINQueryState createState() => _VINQueryState();
}

class _VINQueryState extends State<VINQuery> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(
                left: setWidth(15), right: setWidth(15), top: setWidth(21)),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(3),
                border: Border.all(
                    color: Color(0xff323232), width: setWidth(0.5))),
            height: setWidth(150),
            alignment: Alignment.center,
            child: Container(
              margin:
              EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(2),
                  border: Border.all(
                      color: Color(0xff00C65F), width: setWidth(0.5))),
              height: setWidth(60),
              alignment: Alignment.center,
              child: Row(
                children: [
                  Expanded(
                    child: Container(
                      child: TextField(
                        maxLines: 1,
                        keyboardType: TextInputType.multiline,
                        autofocus: false,
                        style: TextStyle(
                            color: Color(0xff030303), fontSize: setSp(16)),
                        cursorColor: YTTheme.theme,
                        textAlign: TextAlign.start,
                        enableInteractiveSelection: false,
                        inputFormatters: [
                          WhitelistingTextInputFormatter(
                              RegExp("[a-zA-Z]|[0-9.-_]")),
                        ],
                        decoration: InputDecoration(
                            contentPadding: EdgeInsets.only(left: setWidth(5)),
                            border: InputBorder.none,
                            focusedBorder: InputBorder.none,
                            enabledBorder: InputBorder.none,
                            hintText: '点击输入VIN号码',
                            hintStyle: TextStyle(
                                color: Color(0xffAAAAAA), fontSize: setSp(16))),
                      ),
                    ),
                  ),
                  Container(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            FocusScope.of(context).requestFocus(FocusNode());
                            _customBottomSheet();
//                                    Navigator.push(context, MaterialPageRoute(builder: (context) {
//                                      return CustomCamera();
//                                    }));
                          },
                          child: Container(
                              width: setWidth(76),
                              alignment: Alignment.center,
                              child: Column(
                                children: [
                                  Container(
                                    width: setWidth(20),
                                    height: setWidth(17),
                                    child: Image.asset(
                                      "assets/images/camera.png",
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  SizedBox(
                                    height: setWidth(5),
                                  ),
                                  Container(
                                    child: Text(
                                      "拍照识别",
                                      style: TextStyle(
                                          color: Color(0xff989898),
                                          fontSize: setSp(12)),
                                    ),
                                  ),
                                ],
                              )),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
          ),
          GestureDetector(
            onTap: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) =>RepairsInquiry(), settings: RouteSettings(name: 'repairs_inquiry'),));
//              urlPush(context, "yuntu://repairs_inquiry");

            },
            child: Container(
              margin: EdgeInsets.only(
                  left: setWidth(15),
                  right: setWidth(15),
                  top: setWidth(54)),
              decoration: BoxDecoration(
                  color: Color(0xff00C65F),
                  borderRadius: BorderRadius.circular(3)),
              height: setWidth(44),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    "查询",
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: setSp(15),
                        fontWeight: FontWeight.w600),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  ///自定义底部弹窗
  void _customBottomSheet() {
    showModalBottomSheet(
        backgroundColor: Colors.white,
        context: context,
        builder: (BuildContext context) {
          return Container(
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  GestureDetector(
                    onTap: () {
                      ///去拍照
                      _checkImage(1);
                      Navigator.of(context).pop();
                    },
                    child: Container(
                        height: setWidth(52),
                        decoration: BoxDecoration(
                          color: Colors.white,
                        ),
                        child: Center(
                            child: simpleText("拍照", color: YTStyle.textColor))),
                  ),
                  Container(
                    height: setWidth(0.5),
                    color: Color(0xffDDDDDD),
                  ),
                  GestureDetector(
                    onTap: () {
                      ///相册选择
                      _checkImage(0);
                      Navigator.of(context).pop();
                    },
                    child: Container(
                        height: setWidth(52),
                        decoration: BoxDecoration(
                          color: Colors.white,
                        ),
                        child: Center(
                          child: simpleText("图库", color: YTStyle.textColor),
                        )),
                  ),
                  Container(
                    height: setWidth(0.5),
                    color: Color(0xffDDDDDD),
                  ),
                  Container(
                    height: setWidth(10),
                    color: Color(0xffF0F0F0),
                  ),
                  GestureDetector(
                    onTap: () => Navigator.of(context).pop(),
                    child: Container(
                        height: setWidth(52),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(3.0),
                        ),
                        child: Center(
                          child: simpleText("取消", color: YTStyle.textColor),
                        )),
                  )
                ],
              ),
            ),
          );
        });
  }

  ///
  _checkImage(int type) async {
    if (type == 0) {
      await ImagePicker.pickImage(
        source: ImageSource.gallery,
      ).then((value) {
        if (value != null) {
        }
      });
    } else {
      await ImagePicker.pickImage(
        source: ImageSource.camera,
      ).then((value) {
        if (value != null) {
        }
      });
    }
  }
}
